package com.yxym.homework;

import java.nio.channels.UnsupportedAddressTypeException;

public class Homework07 {
    public static void main(String[] args) {
        Shape shape = ShapeDemo.getShape("圆形");
        shape.erase();
        shape.draw();
    }
}
interface Shape {
    void draw();
    void erase();

}
class Circle implements Shape{
    public Circle(){
        System.out.println("创建圆形");
    }

    @Override
    public void draw() {
        System.out.println("画出圆形");
    }

    @Override
    public void erase() {
        System.out.println("清除圆形");
    }
}
class Triangle implements Shape{
    public Triangle(){
        System.out.println("创建三角形");
    }

    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }

    @Override
    public void erase() {
        System.out.println("清除三角形");
    }
}

class Rectangle implements Shape{
    public Rectangle(){
        System.out.println("创建矩形");
    }

    @Override
    public void draw() {
        System.out.println("绘制出矩形");
    }

    @Override
    public void erase() {
        System.out.println("清除矩形");
    }
}
class ShapeDemo {
    public static Shape getShape(String type) throws UnsupportedAddressTypeException {
        Shape shape = null;
        if(type.equalsIgnoreCase("圆形"))
            shape = new Circle();
        if(type.equalsIgnoreCase("三角形"))
            shape = new Triangle();
        if(type.equalsIgnoreCase("矩形"))
            shape = new Rectangle();
//        else {
//            throw new UnsupportedAddressTypeException();
//        }
            return shape;
    }
}